from PySide2 import QtGui, QtCore, QtWidgets
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
import sys


class Demo(QWidget):
    def __init__(self, parent=None):
        super(Demo, self).__init__(parent)
        self.setWindowTitle('画刷的设置')
        self.resize(430, 250)

    def paintEvent(self, event):
        painter = QPainter(self)
        brush = QBrush()
        # 创建第1列的矩形及标识文字
        # 设置第1个矩形的画刷
        brush.setColor(Qt.red)
        brush.setStyle(Qt.SolidPattern)
        painter.setBrush(brush)
        painter.drawRect(10, 10, 30, 30)
        painter.drawText(50, 30, "纯色样式")
        # 设置第2个矩形的画刷
        brush.setColor(Qt.blue)
        brush.setStyle(Qt.Dense1Pattern)
        painter.setBrush(brush)
        painter.drawRect(10, 50, 30, 30)
        painter.drawText(50, 70, "密度样式1")
        # 设置第3个矩形的画刷
        brush.setColor(Qt.cyan)
        brush.setStyle(Qt.Dense2Pattern)
        painter.setBrush(brush)
        painter.drawRect(10, 90, 30, 30)
        painter.drawText(50, 110, "密度样式2")
        # 设置第4个矩形的画刷
        brush.setColor(Qt.green)
        brush.setStyle(Qt.Dense3Pattern)
        painter.setBrush(brush)
        painter.drawRect(10, 130, 30, 30)
        painter.drawText(50, 150, "密度样式3")
        # 设置第5个矩形的画刷
        brush.setColor(Qt.black)
        brush.setStyle(Qt.Dense4Pattern)
        painter.setBrush(brush)
        painter.drawRect(10, 170, 30, 30)
        painter.drawText(50, 190, "密度样式4")
        # 设置第6个矩形的画刷
        brush.setColor(Qt.darkMagenta)
        brush.setStyle(Qt.Dense5Pattern)
        painter.setBrush(brush)
        painter.drawRect(10, 210, 30, 30)
        painter.drawText(50, 230, "密度样式5")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = Demo()
    demo.show()
    sys.exit(app.exec_())







